/*

有一个无符号32bit（bit31, …, bit1, bit0）的数a，
设置a的值为0x7777；
1) 取出a的bit15..bit7；
2)将a的bit18设置为1，其他位不变；
3)将a的bit15..bit13设置为0，其他位保持不变。

 */

#include <stdio.h>
#include <stdlib.h>
int main()
{
	unsigned int a, b;
	// a = rand();
	a = 0x7777;
	printf("0x%x\n", a);
	//1) method 1
	b = a << 16;
	b = b >> 23;
	printf("1)method 1:\n 0x%x\n", b);
	//1)method 2
	b = 0xFF80;
	b = a & b;
	b = b >> 7;
	printf("1)method 2:\n 0x%x\n", b);
	//2) method 1
	b = a | (1 << 18);
	printf("2)method 1\n 0x%x\n", b);
	//2) method 2
	b = 0x400000000  //...0100 0000 0000 0000 0000
	b = a | (1 << 18);
	printf("2)method 2\n 0x%x\n", b);


	b = 0x7 << 13;
	b = a & (~b);
	printf("0x%x\n", b);
}
